Distributed database systems are utilized extensively for many applications. If an application needs to access multiple resource managers (database servers) in a single transaction, then the XA protocol should be used to ensure that the state remains consistent between them. The XA protocol supports the use of two-phase commit, ensuring that modifications between the multiple resources either commit together or are rolled back together. It should be noted that for many resource managers, using XA adds substantial overhead to all operations, not just the commit. As a result, XA should be used only when necessary. Resource managers (database servers) that do not “know” about one another can not cooperate directly in distributed transactions. (Example: a transaction may span over an Informix, DB2 and Oracle database.) Instead, the transaction manager controls the transaction, indicating to each resource manager whether and when to commit or roll back, based on the global state of the transaction. A transaction manager coordinates transactions between resource managers using a two-phase commit protocol. The two-phase commit protocol provides the ACID (Atomicity, Consistency, Isolation, Durability) properties of transactions across multiple resources.
In the first phase of two-phase commit, the transaction manager tells each resource to “prepare” to commit; that is, to perform all operations for a commit and be ready either to make the changes permanent or to undo all changes. Each resource manager responds, indicating whether or not the prepare operation succeeded.
In the second phase, if all prepare operations succeed, the transaction manager tells all resource managers to commit their changes; otherwise, it tells them all to roll back and indicates transaction failure to the application.
A particular resource manager may participate in multiple simultaneous distributed transactions. The ACID properties apply for all resource managers involved in a particular distribute transaction, as well as for all pending transactions within a particular resource manager.
A distributed transaction protocol, such as XA includes, i.e., a 2 phase commit mechanism supported by major database vendors, transaction managers and client tool vendors. The protocol involves xa_open followed by xa_close which are used to enable/disable distributed transactions equivalent to a database open and database close statements in a normal connection/transaction scenario. The xa_open and xa_close calls both require a considerable amount of time because they require accessing resource managers on the network. Therefore, it is desirable to optimize the number of open and close calls to minimize the time required to execute transactions.